package tingshu.servlet.album;

import lombok.SneakyThrows;
import tingshu.util.DBUtil;
import tingshu.util.Log;
import tingshu.view_object.UserVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

@WebServlet("/studio/album/withdraw.do")
public class WithdrawDoServlet extends HttpServlet {
    @Override
    @SneakyThrows
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        int aid = Integer.parseInt(req.getParameter("aid"));

        try (Connection c = DBUtil.connection()) {
            String sql = "update albums set state = 1 where aid = ?";
            try (PreparedStatement ps = c.prepareStatement(sql)) {
                ps.setInt(1, aid);
                Log.println("执行 SQL" + ps);
                ps.executeUpdate();
            }
        }
        resp.sendRedirect("/studio/album/list.html");
    }
}
